package com.finance.system.user.controller;

import com.finance.system.user.entity.GroupEntity;
import com.finance.system.user.entity.UserEntity;
import com.finance.system.user.entity.UserGroupRelationEntity;
import com.finance.system.support.bean.ResultBean;
import com.finance.system.user.entity.GroupInbound;
import com.finance.system.user.service.IUserGroupRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created with IDEA
 *
 * @author: 董文辉
 * Date: 2018/1/8
 * Time: 16:45
 */
@RestController
@RequestMapping("userGroup")
public class UserGroupController  extends BaseController {
    @Autowired
    private IUserGroupRelationService userGroupRelationService;

    /**
     * 查询用户的所有账本
     * @param paraMap
     * @return
     */
    @RequestMapping("getGroupByUserId")
    @ResponseBody
    public ResultBean<List<GroupEntity>> getGroupByUserId(@RequestBody Map<String,Object> paraMap){
        return userGroupRelationService.getGroupByUserId((String)paraMap.get("id"));
    }
    /**
     * 根据账本id查询所有组成员
     * @param paraMap
     * @return
     */
    @RequestMapping("getUserByGroupId")
    @ResponseBody
    public ResultBean<List<UserEntity>> getUserByGroupId(@RequestBody Map<String,Object> paraMap){
        return userGroupRelationService.getUserByGroupId((String)paraMap.get("id"));
    }

    /**
     * 账本编辑
     * @param group
     * @return
     */
    @RequestMapping("updateGroup")
    @ResponseBody
    public ResultBean<GroupEntity> updateGroup(@RequestBody GroupInbound group){
        return userGroupRelationService.updateGroup(group);
    }

    /**
     * 新增账本
     * @param group
     * @return
     */
    @RequestMapping("addOne")
    @ResponseBody
    public ResultBean<GroupEntity> addOne(@RequestBody GroupInbound group){
        return userGroupRelationService.addOne(group);
    }

    /**
     * 为账本添加y用户
     * @param relation
     * @return
     */
    @RequestMapping("addUserInToGroup")
    @ResponseBody
    public ResultBean addUserInToGroup(@RequestBody UserGroupRelationEntity relation){
        return userGroupRelationService.addUserInToGroup(relation);
    }

}
